package com.jia.train.batch.job;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.jia.train.batch.feign.TrainSeatFeignClient;
import com.jia.train.global.response.BaseResponse;
import com.jia.train.global.utils.SnowIdUtil;
import jakarta.annotation.Resource;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.util.StopWatch;

@DisallowConcurrentExecution
public class DailyTripsQuartzJob implements Job {

    @Resource
    TrainSeatFeignClient trainSeatFeignClient;

    public static final Logger logger = LoggerFactory.getLogger(DailyTripsQuartzJob.class);

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {

        MDC.put("LOG_ID", SnowIdUtil.getStringSnowNextId());

        logger.info("开始生成每日车次");
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();

        DateTime now = DateTime.now();
        DateTime dateTime = DateUtil.offsetDay(now, 14);
        BaseResponse<String> result
                = trainSeatFeignClient.genDailyTrip(dateTime.toJdkDate());

        stopWatch.stop();
        logger.info("结束 15天后 生成每日车次数据,结果：{}，耗时：{}ms", result.isSuccess(), stopWatch.getTotalTimeMillis());
    }

}
